﻿using ScrappyDB.Utilities;
using NUnit.Framework;
using System;

namespace ScrappyDB.UnitTests
{


    /// <summary>
    ///This is a test class for DbDateTimeTest and is intended
    ///to contain all DbDateTimeTest Unit Tests
    ///</summary>
    [TestFixture()]
    public class DbDateTimeTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }


        /// <summary>
        ///A test for DateTimeToUnixTimeStamp
        ///</summary>
        [Test()]
        public void DateTimeToUnixTimeStampTest()
        {
            DateTime dateTime = DateTime.Now.ToUniversalTime();
            double ts = DbDateTime.DateTimeToUnixTimeStamp(dateTime);

            Assert.IsTrue(dateTime - DbDateTime.UnixTimeStampToDateTime(ts) < new TimeSpan(0, 0, 1));

        }

        /// <summary>
        ///A test for ConvertDateTimeToIso8601
        ///</summary>
        [Test()]
        public void ConvertDateTimeToIso8601Test()
        {
            DateTime dateTime = DateTime.Now.ToUniversalTime();
            string iso = DbDateTime.ConvertDateTimeToIso8601(dateTime);

            Assert.IsTrue(dateTime - DbDateTime.ConvertIso8601ToDateTime(iso) < new TimeSpan(0, 0, 1));
        }


        [Test()]
        public void TsTo8601Test()
        {
            long ts = 1260958793;
            string expected = "2009-12-16T10:19:53Z";

            DateTime dateTime = DbDateTime.UnixTimeStampToDateTime(ts);
            string actual = DbDateTime.ConvertDateTimeToIso8601(dateTime);

            Assert.AreEqual(expected, actual);
        }

    }
}
